package com.xsm.ppsecret.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.jaeger.library.StatusBarUtil;
import com.xsm.ppsecret.R;
import com.xsm.ppsecret.presenter.RegistPresenter;
import com.xsm.ppsecret.ui.implview.IRegistActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RegistActivity extends BaseActivity implements IRegistActivity {
    @BindView(R.id.et_root_first)
    EditText etRootFirst;
    @BindView(R.id.et_root_second)
    EditText etRootSecond;
    @BindView(R.id.et_one_first)
    EditText etOneFirst;
    @BindView(R.id.et_one_second)
    EditText etOneSecond;
    @BindView(R.id.et_two_first)
    EditText etTwoFirst;
    @BindView(R.id.et_two_second)
    EditText etTwoSecond;
    @BindView(R.id.et_encrypted_question)
    EditText etQuestion;
    @BindView(R.id.et_encrypted_answer)
    EditText etAnswer;
    @BindView(R.id.btn_regist)
    Button registBtn;
    private RegistPresenter mPresenter = new RegistPresenter(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first_set);
        ButterKnife.bind(this);
        StatusBarUtil.setColor(this, getResources().getColor(R.color.appColor), 0);
        registBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                regist();
            }
        });
    }

    @Override
    public void regist() {
        mPresenter.regist(etRootFirst.getText().toString(), etRootSecond.getText().toString(), etOneFirst.getText().toString(), etOneSecond.getText().toString(), etTwoFirst.getText().toString(), etTwoSecond.getText().toString(), etQuestion.getText().toString(), etAnswer.getText().toString());
    }

    @Override
    public void verifyError(String errorMsg) {
        Toast.makeText(this, errorMsg, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void verifyOk() {
        startActivity(new Intent(this, LoginActivity.class));
        finish();
    }
}
